// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var base = require("base");
	var databind = require("databind");
	var enterpriseId;
	var bulkstockInfoId;
	var goodsName;

	var init = function() {
		bulkstockInfoId = base.getUrlParam("bulkstockInfoId");
		goodsName = base.getUrlParam("goodsName");
		initEvent();
	};
	var initEvent = function() {
		inquireRankingDatas(enterpriseId, bulkstockInfoId);
	};

	var inquireRankingDatas = function(enterpriseId, bulkstockInfoId) {
		base.fnAjax({
			action: "inquireRankingDatas.json",
			async: true,
			nocode: true,
			oData: {
				type: 3,
				bulkstockInfoId: bulkstockInfoId,
				enterpriseId: enterpriseId
			}, //传递参数
			fnSuccess: function(data) {
				if(data.status == 200) {
					data.x = [];
					data.y = [];
					$.each(data.datas, function() {
						var _this = this;
						data.x.push(_this.name);
						data.y.push(_this.value);
					});
					showChart1(data);
				} else { 
					layer.msg(data.message);
				}
			}
		});
	};
	
	var showChart1 = function(d) {
		// 基于准备好的dom，初始化echarts实例
			var myChart3 = echarts.init(document.getElementById('main4'));
			var localurl = location.href;

//			var r = getParameter("goodsName", localurl);
//			r = decodeURI(r);
			// alert("====="+r); 
//			var vessel = r.substring(r.indexOf("=") + 1, r.length);
			var vessel = decodeURI(goodsName);
			//alert("货名:"+encodeURIComponent(vessel));

			var option = {
				color: ['#3398DB'],
				title: {
					text: '客户放款排行-' + vessel,
					subtext: '一润供应链'
				},
				tooltip: {
					trigger: 'axis'
				},
				legend: {
					data: ['放款']
				},
				tooltip: {
					trigger: 'axis',
					axisPointer: { // 坐标轴指示器，坐标轴触发有效
						type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
					}
				},
				grid: {
					left: '3%',
					right: '4%',
					bottom: '3%',
					containLabel: true
				},
				toolbox: {
					show: true,
					feature: {
						dataView: {
							show: true,
							readOnly: false
						},
						magicType: {
							show: true,
							type: ['line', 'bar']
						},
						restore: {
							show: true
						},
						saveAsImage: {
							show: true
						}
					}
				},
				calculable: true,
//				xAxis: [{
//					type: 'category',
//					data: d.x.slice(0, 10),
//					axisTick: {
//						alignWithLabel: true
//					}
//				}],
//				yAxis: [{
//					type: 'value'
//				}],
				xAxis: [{
					type: 'category',
					boundaryGap: false,
					data: d.x.slice(0, 10),
					show: true,
					axisLabel: {
						interval: 0,
						formatter: function(val) {
							return val.split("").join("\n");
						}
					}
				}],
				yAxis: [{
					type: 'value'
				}],
				series: [{
					name: '收款',
					type: 'bar',
					barWidth: '60%',
					label: {
						normal: {
							show: true,
							position: 'inside'
						}
					},
					data: d.y.slice(0, 10)
				}]
			};

			// 使用刚指定的配置项和数据显示图表。
			myChart3.setOption(option);
	};

	return {
		init: init
	};
});